package com.leo.blog.login.handler;




import com.leo.blog.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/11 15:08
 * @since JDK 1.8
 */
@Component
@Slf4j
public class UserAuthenticationEntryPointHandler implements AuthenticationEntryPoint {
    /**
     * 用户未登录返回结果
     * @Author Sans
     * @CreateTime 2019/10/3 9:01
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
        try {
            response.setStatus(402);
            ResultUtil.responseJson(response,ResultUtil.resultCode(402,"未登录"));
        }catch (Exception e){
            e.printStackTrace();
        }

    }

}
